﻿using System.Collections.Generic;
using System.Linq;
using WorkFlowCore.Plugins;

namespace WorkFlowCore.Host.ViewModels.Plugins
{
    public class CustomizationVerifyExtensionDto
    {
        /// <summary>
        /// 插件id
        /// </summary>
        public string PluginId { get; set; }
        /// <summary>
        /// 插件名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }


        public static CustomizationVerifyExtensionDto[] FromPluginApplyConfig(List<PluginApplyConfig> pluginApplyConfigs,IEnumerable<ManifestWithConfig> manifestWithConfigs)
        {
            var result = pluginApplyConfigs.Select(c =>
            {
                var manifest = manifestWithConfigs.FirstOrDefault(m => m.ClassName == c.EntryFullName);
                return new CustomizationVerifyExtensionDto
                {
                    Description = c.Description?? manifest?.Description,
                    PluginId = c.PluginId,
                    Name = c.Name,
                };
            }).ToArray();
            return result;
        }
    }
}
